|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectcontrolP5.ControllerGroup
controlP5.ControlGroup
controlP5.RadioButton
public class RadioButton
a radio button implementation. a radioButton is a list of toggles that can be turned on or off. radioButton is of type ControllerGroup, therefore a controllerPlug can't be set. this means that an event from a radioButton can't be forwarded to a method other than controlEvent in a sketch. a radioButton has 2 sets of values. radioButton.value() returns the value of the active radioButton item. radioButton.arrayValue() returns a float array that represents the active (1) and inactive (0) items of a radioButton. ControlP5 CheckBox Toggle
/**
* ControlP5 RadioButton
* by andreas schlegel, 2009
*/
import controlP5.*;
ControlP5 controlP5;
int myColorBackground = color(0,0,0);
RadioButton r;
void setup() {
size(400,400);
smooth();
controlP5 = new ControlP5(this);
r = controlP5.addRadioButton("radioButton",20,160);
r.setColorForeground(color(120));
r.setColorActive(color(255));
r.setColorLabel(color(255));
r.setItemsPerRow(5);
r.setSpacingColumn(50);
addToRadioButton(r,"50",1);
addToRadioButton(r,"100",2);
addToRadioButton(r,"150",3);
addToRadioButton(r,"200",4);
addToRadioButton(r,"250",5);
}
void addToRadioButton(RadioButton theRadioButton, String theName, int theValue ) {
Toggle t = theRadioButton.addItem(theName,theValue);
t.captionLabel().setColorBackground(color(80));
t.captionLabel().style().movePadding(2,0,-1,2);
t.captionLabel().style().moveMargin(-2,0,0,-3);
t.captionLabel().style().backgroundWidth = 46;
}
void draw() {
background(myColorBackground);
}
void keyPressed() {
if(key==' ') {
r.deactivateAll();
} else if (key=='a') {
r.activate("50");
} else if(key>='0' && key<'5') {
// convert a key-number (48-52) to an int between 0 and 4
int n = int(key)-48;
r.activate(n);
}
}
void controlEvent(ControlEvent theEvent) {
print("got an event from "+theEvent.group().name()+"\t");
for(int i=0;i| Field Summary |
|---|
| Fields inherited from interface controlP5.ControlP5Constants |
|---|
acceptClassList, ACTIVE, ALT, ARC, ARRAY, BACKSPACE, BOOLEAN, BOTTOM, CENTER, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FIELD, FLOAT, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IMAGE, INCREASE, INTEGER, INVALID, KEYCONTROL, LEFT, LINE, LOAD, MENU, METHOD, MOVE, OVER, PI, PRESSED, PRINT, RELEASE, RESET, RIGHT, SAVE, SHIFT, SPRITE, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, TAB, TOP, TWO_PI, UP, VERBOSE, VERTICAL |
| Constructor Summary | |
|---|---|
RadioButton(ControlP5 theControlP5,
ControllerGroup theParent,
java.lang.String theName,
int theX,
int theY)
|
|
| Method Summary | |
|---|---|
void |
activate(int theIndex)
deactivate the currently active radio button and make a new radio button active. |
void |
activate(java.lang.String theRadioButtonName)
active an item of the Radio button by name. |
Toggle |
addItem(java.lang.String theName,
float theValue)
add items to a radioButton/checkBox. |
Toggle |
addItem(Toggle theToggle,
float theValue)
add items to a radioButton/checkBox. |
void |
controlEvent(ControlEvent theEvent)
controlEvent is called whenever a radioButton item is (de-)activated. |
void |
deactivate(int theIndex)
deactivate a radio button. |
void |
deactivate(java.lang.String theRadioButtonName)
deactivate a RadioButton and set the value of the radio controller to the default value (-1). |
void |
deactivateAll()
deactivate all radioButton items. |
Toggle |
getItem(int theIndex)
get an item from the list of toggles by index. |
boolean |
getState(int theIndex)
get the state of a checkBox item - which can be true (for on) and false (for off). |
boolean |
getState(java.lang.String theRadioButtonName)
get the state of a checkBox item - which can be true (for on) and false (for off). |
void |
removeItem(java.lang.String theName)
remove an item from the radioButton/checkBox list. |
processing.core.PImage |
setImage(processing.core.PImage theImage)
Controller.DEFAULT (background) Controller.OVER (foreground) Controller.ACTIVE (active) |
processing.core.PImage |
setImage(processing.core.PImage theImage,
int theState)
|
RadioButton |
setImages(processing.core.PImage theImage1,
processing.core.PImage theImage2,
processing.core.PImage theImage3)
|
void |
setItemHeight(int theItemHeight)
set the height of a radioButton/checkBox item. |
void |
setItemsPerRow(int theValue)
items for a radioButton or a checkBox are organized in columns and rows. |
void |
setItemWidth(int theItemWidth)
set the width of a radioButton/checkBox item. |
void |
setNoneSelectedAllowed(boolean theValue)
in order to always have 1 item selected, use setNoneSelectedAllowed(false). |
void |
setSize(int theWidth,
int theHeight)
|
void |
setSize(processing.core.PImage theImage)
|
void |
setSpacingColumn(int theSpacing)
set the (pixel) spacing between columns. |
void |
setSpacingRow(int theSpacing)
set the (pixel) spacing between rows. |
void |
toggle(int theIndex)
|
java.lang.String |
toString()
|
void |
updateLayout()
|
| Methods inherited from class controlP5.ControlGroup |
|---|
activateEvent, addCloseButton, addToXMLElement, arrayValue, getBackgroundHeight, hideBar, isBarVisible, mousePressed, removeCloseButton, setArrayValue, setBackgroundColor, setBackgroundHeight, setBarHeight, showBar, stringValue, value |
| Methods inherited from class controlP5.ControllerGroup |
|---|
absolutePosition, add, addCanvas, addDrawable, captionLabel, close, color, continuousUpdateEvents, controller, disableCollapse, draw, enableCollapse, getAsXML, getColor, getHeight, getPickingColor, getTab, getWidth, getWindow, hide, id, init, isCollapse, isMoveable, isOpen, isUpdate, isVisible, isXMLsavable, keyEvent, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, name, open, parent, position, remove, remove, remove, removeCanvas, setColorActive, setColorBackground, setColorForeground, setColorLabel, setColorValue, setGroup, setGroup, setHeight, setId, setLabel, setMousePressed, setMoveable, setOpen, setPosition, setTab, setTab, setTab, setUpdate, setVisible, setWidth, show, update, updateAbsolutePosition, updateEvents, updateInternalEvents, valueLabel |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public RadioButton(ControlP5 theControlP5,
ControllerGroup theParent,
java.lang.String theName,
int theX,
int theY)
| Method Detail |
|---|
public Toggle addItem(java.lang.String theName,
float theValue)
theName - theValue -
public Toggle addItem(Toggle theToggle,
float theValue)
theToggle - theValue -
public void removeItem(java.lang.String theName)
theName -
public RadioButton setImages(processing.core.PImage theImage1,
processing.core.PImage theImage2,
processing.core.PImage theImage3)
public processing.core.PImage setImage(processing.core.PImage theImage)
theImage -
public processing.core.PImage setImage(processing.core.PImage theImage,
int theState)
public void setSize(processing.core.PImage theImage)
public void setSize(int theWidth,
int theHeight)
public void setItemHeight(int theItemHeight)
theItemHeight - public void setItemWidth(int theItemWidth)
theItemWidth - public Toggle getItem(int theIndex)
theIndex -
public boolean getState(int theIndex)
theIndex -
public boolean getState(java.lang.String theRadioButtonName)
theRadioButtonName -
public void updateLayout()
public void setItemsPerRow(int theValue)
theValue - public void setSpacingColumn(int theSpacing)
theSpacing - public void setSpacingRow(int theSpacing)
theSpacing - public void deactivateAll()
public void activate(int theIndex)
theIndex - public void deactivate(int theIndex)
theIndex - public void activate(java.lang.String theRadioButtonName)
theRadioButtonName - public void deactivate(java.lang.String theRadioButtonName)
theRadioButtonName - public void toggle(int theIndex)
public void controlEvent(ControlEvent theEvent)
controlEvent in interface ControlListenercontrolEvent in class ControlGrouptheEvent - ControlEvent
Controllerpublic void setNoneSelectedAllowed(boolean theValue)
theValue - public java.lang.String toString()
toString in class ControlGroup
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||